<?php

namespace App\Http\Requests\Common;

use App\Http\Models\Common\CryptDES3;
use App\Http\Requests\Request;

class BaseRequest extends Request
{
    //
    public function authorize()
    {
        return true;
    }
    //
    public function rules()
    {
        return [];
    }
    //
    public function __construct()
    {
        //管理员信息
        $this->admin = session('admin');
        if (!is_null($this->admin)) {
            $this->admin['auth'] = config('menu');
        }
    }
    //
    public static function _env()
    {
        $host   = self::getHost();
        $status = filter_var($host, FILTER_VALIDATE_IP);
        return $status ? true : false;
    }
    //
    public static function _toArray($obj = '')
    {
        return json_decode(json_encode($obj), 1);
    }
    //
    public static function _json($data = [], $status = 0, $msg = '', $redirect_uri = '')
    {
        return \Response::json(['status' => $status, 'data' => $data, 'msg' => $msg, 'redirect_uri' => $redirect_uri]);
    }
    //
    public static function dataEncode($str = '')
    {
        $key     = env('DES3_KEY');
        $iv      = env('DES3_IV');
        $des3    = new CryptDES3($key, $iv);
        $encrypt = $des3->encrypt($str);
        return $encrypt;
    }
    //
    public static function dataDecode($str = '')
    {
        $key     = env('DES3_KEY');
        $iv      = env('DES3_IV');
        $des3    = new CryptDES3($key, $iv);
        $decrypt = $des3->decrypt($str);
        return $decrypt;
    }
    //
    public static function _get($url = '', $query = [])
    {
        $base_uri = env('CGI_URI');
        $client   = new \GuzzleHttp\Client(['base_uri' => $base_uri]);
        $res      = $client->request('GET', $url, ['query' => $query])->getBody()->getContents();
        return $res;
    }
}
